package com.wanmait.recruitment.service.impl;

import com.github.pagehelper.PageInfo;
import com.wanmait.recruitment.mapper.AdminMapper;
import com.wanmait.recruitment.pojo.Admin;
import com.wanmait.recruitment.service.AdminService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
@Service("AdminService")
@Transactional(rollbackFor = Exception.class)
public class AdminServiceImpl implements AdminService

{

    private Logger logger = LogManager.getLogger(AdminServiceImpl.class);

    @Resource
    private AdminMapper adminMapper;

    @Override
    @CacheEvict(value = "adminCache",allEntries = true)
    public void insert(Admin object) {
        adminMapper.insert(object);
    }

    @Override
    public void delete(Integer id) {

    }

    @Override
    public void delete(String ids) {

    }

    @Override
    @CacheEvict(value = "adminCache",allEntries = true)
    public void update(Admin object) {
        adminMapper.updateByAdmin(object);
    }

    @Override
    public Admin findById(Integer id) {
        return null;
    }

    @Override
    @Cacheable("adminCache")
    public List<Admin> findAll() {
        return adminMapper.selectList();
    }

    @Override
    public List<Admin> findAll(Admin object) {
        return null;
    }

    @Override
    public PageInfo<Admin> findPage(int pageNum, int pageSize) {
        return null;
    }

    @Override
    public Admin login(Admin admin) {
        return adminMapper.login(admin);
    }

    @Override
    @CacheEvict(value = "adminCache",allEntries = true)
    public void updateLoginCount(Admin admin) {
        adminMapper.updateLoginCount(admin);
    }

    @Override
    public Admin findByUsername(String username) {
        return adminMapper.selectByUsername(username);
    }

    @Override
    @CacheEvict(value = "adminCache",allEntries = true)
    public void batchOpreate(Integer[] ids) {
        adminMapper.batchOpreate(ids);
    }
}
